package io.renren.modules.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.modules.demo.dao.DhUserInfoDao;
import io.renren.modules.demo.dto.ChildFourData;
import io.renren.modules.demo.dto.ChildOneData;
import io.renren.modules.demo.dto.DhUserInfoDTO;
import io.renren.modules.demo.entity.DhUserInfoEntity;
import io.renren.modules.demo.service.DhUserInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2023-03-25
 */
@Service
public class DhUserInfoServiceImpl extends CrudServiceImpl<DhUserInfoDao, DhUserInfoEntity, DhUserInfoDTO> implements DhUserInfoService {

    @Autowired
    private DhUserInfoDao dhUserInfoDao;

    @Override
    public QueryWrapper<DhUserInfoEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");

        QueryWrapper<DhUserInfoEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }


    /**
     * 获取租物人姓名
     *
     * @param userId
     * @return
     */
    @Override
    public String getRentUserName(Integer userId) {
        DhUserInfoEntity dhUserInfoEntity = dhUserInfoDao.selectById(userId);
        return dhUserInfoEntity.getUserName();
    }

    /**
     * 获取俱乐部会员学历分布数据
     *
     * @return
     */
    @Override
    public List<ChildFourData> getChildFourData() {
        return dhUserInfoDao.getChildFourData();
    }

    /**
     * 获取男性、女性用户人数
     *
     * @return
     */
    @Override
    public List<Integer> getChildOneInnerData() {
        Integer maleUser = dhUserInfoDao.getMaleUser();
        Integer femaleUser = dhUserInfoDao.getFemaleUser();
        List<Integer> list = new ArrayList<>();
        list.add(maleUser);
        list.add(femaleUser);
        return list;
    }

    /**
     * 获取不同年龄段用户人数
     *
     * @return
     */
    @Override
    public List<ChildOneData> getChildOneOuterData() {
        ChildOneData childOneData1 = new ChildOneData();
        ChildOneData childOneData2 = new ChildOneData();
        ChildOneData childOneData3 = new ChildOneData();
        ChildOneData childOneData4 = new ChildOneData();
        List<ChildOneData> list = new ArrayList<>();
        Integer tenToTwentyNum = dhUserInfoDao.getTenToTwentyNum();
        childOneData1.setAgeRange("10-20岁");
        childOneData1.setNum(tenToTwentyNum);
        list.add(childOneData1);
        Integer twentyOneToThirtyNum = dhUserInfoDao.getTwentyOneToThirtyNum();
        childOneData2.setAgeRange("21-30岁");
        childOneData2.setNum(twentyOneToThirtyNum);
        list.add(childOneData2);
        Integer thirtyOneToFortyNum = dhUserInfoDao.getThirtyOneToFortyNum();
        childOneData3.setAgeRange("31-40岁");
        childOneData3.setNum(thirtyOneToFortyNum);
        list.add(childOneData3);
        Integer fortyOneToFiftyNum = dhUserInfoDao.getFortyOneToFiftyNum();
        childOneData4.setAgeRange("41-50岁");
        childOneData4.setNum(fortyOneToFiftyNum);
        list.add(childOneData4);
        return list;
    }

    /**
     * 获取俱乐部会员总数
     *
     * @return
     */
    @Override
    public Integer getChildTwoData() {
        return dhUserInfoDao.getChildTwoData();
    }
}